package cn.datawin.cmppserver.netway.validator;

import cn.datawin.bms.customer.redis.CstmCustomerCmppRedisDto;
import cn.datawin.cmppserver.queue.QueueCache;
import cn.datawin.cmppserver.util.CacheService;
import cn.hutool.extra.spring.SpringUtil;
import com.drondea.sms.type.IValidator;
import com.drondea.sms.type.UserChannelConfig;

import java.util.concurrent.ConcurrentLinkedQueue;

public class TcpValidator implements IValidator {


    /**
     * 登录验证方法
     * @param userName
     * @return
     */
    @Override
    public UserChannelConfig getUserChannelConfig(String userName) {

        // TODO: 2022/11/30
        //获取用户信息
        CstmCustomerCmppRedisDto userInfo = SpringUtil.getBean(CacheService.class).getCustomer(userName);
        if (userInfo == null || userInfo.getStatus() == 0) {
            return null;
        }
        UserChannelConfig userChannelConfig = new UserChannelConfig();
        userChannelConfig.setUserName(userInfo.getCustomerCode());
        userChannelConfig.setPassword(userInfo.getPassword());
        userChannelConfig.setQpsLimit(userInfo.getAcceptRate());
        userChannelConfig.setId(userInfo.getCustomerCode());
        userChannelConfig.setValidIp(userInfo.getIps());
        userChannelConfig.setChannelLimit(userInfo.getConnections());
        userChannelConfig.setWindowSize(32);
        userChannelConfig.setWindowMonitorInterval(10 * 1000);
        userChannelConfig.setRequestExpiryTimeout(30 * 1000);

        // TODO: 2022/11/30
        //InitSystemEnv.addUserInfo(userName, userInfo);
        QueueCache.MESSAGES_REPORT_QUEUE.putIfAbsent(userName, new ConcurrentLinkedQueue<>());
        QueueCache.MESSAGES_INBOX_QUEUE.putIfAbsent(userName, new ConcurrentLinkedQueue<>());
        return userChannelConfig;
    }

}
